package edu.hawaii.webspider;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
 * Test cases for WebSpiderExample.
 *
 * @author Ka Yee Leung
 */
public class TestWebSpiderExample {
  /** webpage to test on. */
  private static final String url = "http://www.google.com";
  /** argument to get most popular. */
  private static final String mostPopular = "-mostpopular";
  
  /**
   * Test case for webTotallinks.
   * 
   * @throws Exception If errors occur while running the main method.
   */
   @Test
    public void testWebTotallinks() throws Exception {
    //test for finding total number of pages without logging
    String[] testArg1 = {"-totallinks", url , "1"};
    WebSpiderExample.main(testArg1);
    //test for find the most popular page without logging
    String[] testArg2 = {mostPopular, url , "1"};
    WebSpiderExample.main(testArg2);
    //passing invalid number of parameters
    String[] testArg3 = {mostPopular, url , "1", "100", "100"};
    WebSpiderExample.main(testArg3);
    //find the most popular page with logging
    String[] testArg4 = {mostPopular, url , "1", "-logging"};
    WebSpiderExample.main(testArg4);
    //find total number of pages with logging
    String[] testArg5 = {"-totallinks", url , "1", "-logging"};
    WebSpiderExample.main(testArg5);
    //passing an invalid parameter for the number of pages
    String[] testArg6 = {mostPopular, url , "not an integer", "-logging"};
    WebSpiderExample.main(testArg6);
    String[] testArg7 = {"-totallinks", url , "not an integer", "100"};
    WebSpiderExample.main(testArg7);
    WebSpiderExample test = new WebSpiderExample(url);
    assertEquals("Testing getNumLink(): ", 28, test.getNumLinks());
   }
  
   /**
    * Test case for main method.
    * 
    * @throws Exception If errors occur while running the main method.
    */
    @Test
     public void testWebitem() throws Exception {
    WebSpiderExample.WebItem item = new WebSpiderExample.WebItem(url);
    assertEquals("Testing webItem constructor: link", url, item.link);
  }
}
